package com.pmsystem.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pmsystem.pojo.Accident;
import com.pmsystem.pojo.CleanArea;
import com.pmsystem.pojo.CleanMan;
import com.pmsystem.pojo.CleanMis;
import com.pmsystem.pojo.SecurityArea;
import com.pmsystem.pojo.SecurityMan;
import com.pmsystem.pojo.SecurityMis;
import com.pmsystem.service.SecurityService;



@Controller
@RequestMapping("admin/security")
public class SecurityController {

	@Autowired
	SecurityService securityService;
	
	/**
	 * <p>Title: index</p >  
	 * <p>Description: 主页路径</p >  
	 * @author 魏家洛
	 * @param mv
	 * @return
	 */
	
	@RequestMapping("index")
	public String index(ModelAndView mv) {
		return "security/security_index";
	}
	
	
	//安保区域操作
		/**
		 * <p>Title: findAreaPage</p >  
		 * <p>Description:传入页码和页大小获取页码对应保洁区域信息</p >  
		 * @author 魏家洛
		 * @param pageNo
		 * @param pageSize
		 * @return
		 */
		@RequestMapping("findareapage")
		@ResponseBody
		public Map findAreaPage(Integer pageNo,Integer pageSize,String condition){
			return securityService.findAreaPage(pageNo,pageSize,condition);
		}
		/**
		 * <p>Title: findAllArea</p >  
		 * <p>Description:传入条件查询所有区域信息</p >  
		 * @author 魏家洛
		 * @param pageNo
		 * @param pageSize
		 * @return
		 */
		@RequestMapping("findallarea")
		@ResponseBody
		public Map<String,Object> findAllArea(String keyword){
			return securityService.findAllArea(keyword);
		}
		/**
		 * <p>Title: deletesecurity</p >  d
		 * <p>Description:删除保洁区域信息</p >  
		 * @author 魏家洛
		 * @param id
		 * @return
		 */
		/**
		 * <p>Title: findAreabyid</p >  
		 * <p>Description: 通过id查找安保区域信息</p >  
		 * @author 魏家洛
		 * @param id
		 * @param mv
		 * @return
		 */
		@RequestMapping("findareabyid")
		@ResponseBody
		public Map<String, Object> findAreabyid(Integer id){
			Map<String, Object> map = new HashMap<>();
			SecurityArea securityArea = securityService.selectArea(id);
			map.put("securityArea", securityArea);
			return map;
		}
		@RequestMapping("deletearea")
		@ResponseBody
		public Map<String,Object> deleteArea(Integer id){
			Map<String,Object> map = new HashMap<>();
			boolean flag = securityService.deleteArea(id);
			if(flag) {
				map.put("msg", "success");
			}
			else{
				map.put("msg", "error");
			}
			return map;
		}
		@RequestMapping("deleteallarea")
		@ResponseBody
		public Map<String,Object> deleteAllArea(int[] id){
			Map<String,Object> map = new HashMap<>();
			boolean flag=false;
			for (int i : id) {
				flag = securityService.deleteArea(i);
			}
			
			if(flag) {
				map.put("msg", "success");
			}
			else{
				map.put("msg", "error");
			}
			return map;
		}
		/**
		 * <p>Title: updateArea</p >  
		 * <p>Description: 更新保洁区域信息</p >  
		 * @author 魏家洛
		 * @param id
		 * @param mv
		 * @return
		 */
		@RequestMapping("updatearea")
		@ResponseBody
		public Map<String,Object> updateArea(SecurityArea securityArea){
			Map<String,Object> map = new HashMap<>();
			boolean flag = securityService.updateArea(securityArea);
			if(flag)
				map.put("msg", "success");
			else
				map.put("msg", "error");
			return map;
		}
		/**
		 * <p>Title: addArea</p >  
		 * <p>Description: 添加安保区域信息</p >  
		 * @author 魏家洛
		 * @param securityAreaName
		 * @return
		 */
		@RequestMapping("addarea")
		@ResponseBody
		public Map<String,Object> addArea(String securityAreaName){
			Map<String,Object> map = new HashMap<>();
			System.out.println(securityAreaName);
			boolean flag = securityService.addArea(securityAreaName);
			if(flag)
				map.put("msg", "success");
			else
				map.put("msg", "error");
			return map;
		}
	
	
	//安保人员操作
		/**
		 * <p>Title: findAllMan</p >  
		 * <p>Description:传入条件查询所有人员信息</p >  
		 * @author 魏家洛
		 * @param condition
		 * @return
		 */
		@RequestMapping("findallman")
		@ResponseBody
		public Map<String, Object> findAllMan(String keyword){
			return securityService.findAllMan(keyword);
		}
	/**
	 * <p>Title: findManPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应安保人员信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findmanpage")
	@ResponseBody
	public Map findManPage(Integer pageNo,Integer pageSize,String condition){
		return securityService.findManPage(pageNo,pageSize,condition);
	}
	/**
	 * <p>Title: deleteMan</p >  
	 * <p>Description:删除安保人员信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deleteman")
	@ResponseBody
	public Map<String, Object> deleteMan(Integer id){
		Map<String, Object> map = new HashMap<>();
		boolean flag = securityService.deleteMan(id);
		if(flag)
			map.put("msg", "success");
		else
			map.put("msg", "error");
		return map;
	}
	@RequestMapping("deleteallman")
	@ResponseBody
	public Map<String,Object> deleteAllMan(int[] id){
		Map<String,Object> map = new HashMap<>();
		boolean flag=false;
		for (int i : id) {
			flag = securityService.deleteMan(i);
		}
		
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: findManbyid</p >  
	 * <p>Description:通过id查找保洁人员信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("findmanbyid")
	@ResponseBody
	public Map<String, Object> findManbyid(Integer id){
		Map<String, Object> map = new HashMap<>();
		SecurityMan securityMan = securityService.selectMan(id);
		map.put("securityMan", securityMan);
		return map;
	}
	/**
	 * <p>Title: updateMan</p >  
	 * <p>Description: 更新安保人员信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("updateman")
	@ResponseBody
	public Map<String,Object> updateMan(SecurityMan securityMan){
		Map<String,Object> map = new HashMap<>();
		boolean flag=securityService.updateMan(securityMan);
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: addMan</p >  
	 * <p>Description: 添加安保人员信息</p >  
	 * @author 魏家洛
	 * @param securityMan
	 * @return
	 */
	@RequestMapping("addman")
	@ResponseBody
	public Map<String,Object> addMan(SecurityMan securityMan){
		Map<String,Object> map = new HashMap<>();
		boolean flag = securityService.addMan(securityMan);
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
		
		
		
	//安保任务操作
	/**
	 * <p>Title: findMisPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应安保任务信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findmispage")
	@ResponseBody
	public Map findMisPage(Integer pageNo,Integer pageSize,String condition,String startTime,String endTime){
		return securityService.findMisPage(pageNo,pageSize,condition,startTime,endTime);
	}
	/**
	 * <p>Title: findAllMis</p >  
	 * <p>Description::查找符合条件的所有安保任务信息</p >  
	 * @author 魏家洛
	 * @return
	 */
	@RequestMapping("findallmis")
	@ResponseBody
	public Map<String, Object> findAllMis(String keyword,String startTime,String endTime){
		return securityService.findAllMis(keyword,startTime,endTime);
	}
	/**
	 * <p>Title: deleteMis</p >  
	 * <p>Description:删除安保任务信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deletemis")
	@ResponseBody
	public Map<String,Object> deleteMis(Integer id){
		Map<String,Object> map = new HashMap<>();
		boolean flag = securityService.deleteMis(id);
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	@RequestMapping("deleteallmis")
	@ResponseBody
	public Map<String,Object> deleteAllMis(int[] id){
		Map<String,Object> map = new HashMap<>();
		boolean flag=false;
		for (int i : id) {
			flag = securityService.deleteMis(i);
		}
		
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: findMisById</p >  
	 * <p>Description: 根据id查找保洁任务信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("findmisbyid")
	@ResponseBody
	public Map<String, Object> findMisById(Integer id){
		Map<String, Object> map = new HashMap<>();
		SecurityMis securityMis =securityService.selectMis(id);
		map.put("securityMis", securityMis);
		return map;
	}
	/**
	 * <p>Title: updateMis</p >  
	 * <p>Description: 更新安保任务信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("updatemis")
	@ResponseBody
	public Map<String,Object> updateMis(SecurityMis securityMis){
		Map<String,Object> map = new HashMap<>();
		boolean flag=securityService.updateMis(securityMis);
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: addMis</p >  
	 * <p>Description: 添加安保任务信息</p >  
	 * @author 魏家洛
	 * @param securityMis
	 * @return
	 */
	@RequestMapping("addmis")
	@ResponseBody
	public Map<String,Object> addMis(SecurityMis securityMis){
		Map<String,Object> map = new HashMap<>();
		boolean flag=securityService.addMis(securityMis);
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: beFinish</p >  
	 * <p>Description:将任务标记为已完成</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("befinish")
	@ResponseBody
	public Map<String, Object> beFinish(Integer id){
		Map<String, Object> map = new HashMap<>();
		boolean flag = securityService.beFinish(id);
		if(flag)
			map.put("msg", "success");
		else
			map.put("msg", "error");
		return map;
	}
	/**
	 * <p>Title: getProgress</p >  
	 * <p>Description:获取当天任务进度</p >  
	 * @author 魏家洛
	 * @return
	 */
	@RequestMapping("getprogress")
	@ResponseBody
	public int getProgress(String currentDate) {
		return securityService.getProgress(currentDate);
	}	
	
	
	//重大事件
	/**
	 * <p>Title: findAllAccident</p >  
	 * <p>Description::查找符合条件的所有重大事件信息</p >  
	 * @author 魏家洛
	 * @return
	 */
	@RequestMapping("findallaccident")
	@ResponseBody
	public Map<String, Object> findAllAccident(String keyword,String startTime,String endTime){
		return securityService.findAllAccident(keyword,startTime,endTime);
	}
	/**
	 * <p>Title: findAccidentPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应重大事件信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findaccidentpage")
	@ResponseBody
	public Map findAccidentPage(Integer pageNo,Integer pageSize,String condition,String time){
		System.out.println(time);
		return securityService.findAccidentPage(pageNo,pageSize,condition,time);
	}
	/**
	 * <p>Title: deleteAccident</p >  
	 * <p>Description:删除重大事件信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deleteaccident")
	@ResponseBody
	public Map<String,Object> deleteAccident(Integer id){
		Map<String,Object> map = new HashMap<>();
		boolean flag=securityService.deleteAccident(id);
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: deleteAllAccident</p >  
	 * <p>Description:删除重大事件信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deleteallaccident")
	@ResponseBody
	public Map<String,Object> deleteAllAccident(int[] id){
		Map<String,Object> map = new HashMap<>();
		boolean flag=false;
		for (int i : id) {
			flag=securityService.deleteAccident(i);
		}
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: findAccidentbyId</p >  
	 * <p>Description:通过id查找保洁人员信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("findaccidentbyid")
	@ResponseBody
	public Map<String, Object> findAccidentbyId(Integer id){
		Map<String, Object> map = new HashMap<>();
		Accident accident = securityService.selectAccident(id);
		map.put("accident", accident);
		return map;
	}
	/**
	 * <p>Title: updateAccident</p >  
	 * <p>Description: 更新重大事件信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	
	@RequestMapping("updateaccident")
	@ResponseBody
	public Map<String,Object> updateAccident(Accident accident){
		Map<String,Object> map = new HashMap<>();
		System.out.println(accident);
		boolean flag=securityService.updateAccident(accident);
		
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
	/**
	 * <p>Title: addMis</p >  
	 * <p>Description: 添加重大事件信息</p >  
	 * @author 魏家洛
	 * @param accident
	 * @return
	 */
	@RequestMapping("addaccident")
	@ResponseBody
	public Map<String,Object> addAccident(Accident accident){
		Map<String,Object> map = new HashMap<>();
		boolean flag=securityService.addAccident(accident);
		if(flag) {
			map.put("msg", "success");
		}
		else{
			map.put("msg", "error");
		}
		return map;
	}
}
